﻿using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using EasyAbp.ProcessManagement.Localization;
using EasyAbp.ProcessManagement.Web.Components.NotificationsOffcanvasWidget;
using EasyAbp.ProcessManagement.Web.Menus;
using EasyAbp.ProcessManagement.Web.Toolbars;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.Ui.LayoutHooks;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;

namespace EasyAbp.ProcessManagement.Web;

[DependsOn(
    typeof(ProcessManagementApplicationContractsModule),
    typeof(AbpAspNetCoreMvcUiThemeSharedModule),
    typeof(AbpAutoMapperModule)
)]
public class ProcessManagementWebModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
        {
            options.AddAssemblyResource(typeof(ProcessManagementResource),
                typeof(ProcessManagementWebModule).Assembly);
        });

        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            mvcBuilder.AddApplicationPartIfNotExists(typeof(ProcessManagementWebModule).Assembly);
        });
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpNavigationOptions>(options =>
        {
            options.MenuContributors.Add(new ProcessManagementMenuContributor());
        });

        Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<ProcessManagementWebModule>();
        });

        context.Services.AddAutoMapperObjectMapper<ProcessManagementWebModule>();
        Configure<AbpAutoMapperOptions>(options => { options.AddMaps<ProcessManagementWebModule>(validate: true); });

        Configure<RazorPagesOptions>(options =>
        {
            //Configure authorization.
        });

        Configure<AbpToolbarOptions>(
            options => { options.Contributors.Add(new ProcessManagementToolbarContributor()); });

        Configure<AbpLayoutHookOptions>(options =>
        {
            options.Add(LayoutHooks.Body.First, typeof(NotificationsOffcanvasWidgetViewComponent));
        });
    }
}